<?php
header("Content-type: text/html; charset=utf-8");
//是否允许跨域进行访问请求
header("Access-Control-Allow-Origin: *");
//用户Token-请直接在后台域名管理中复制
//$userToken = "2b88b940d17bc6b571a19c8489122376";
$userTokens = [
    "268246eca7158d22012dc2985da356c7",
    "cc09e63e26010c669a358169ad7e47ac",
    "9a7aee2a7ffe866a9018a1ad6d2992a0"
];

foreach ($userTokens as $key => $userToken) {
    //请求API,服务器的地址（需更改）如：spread.com =>spread.jiduba.cn
    $callback = 'http://test.ehuiben.cn/api/upgradeTemplate?';
    $callback .= 'time=' . $_POST['time'];
    $callback .= '&did=' . $_POST['did'];
    $callback .= '&token=' . md5($userToken . $_POST['time']);//.$userToken;
    $contents = file_get_contents($callback);
    if (!empty($contents)) {
        $directory = $_POST['domain'] . '/' . $_POST['directory'];
        //目录不存在，创建目录和文件
        if (!is_dir($directory)) {
            mkdir(iconv("UTF-8", "GBK", $directory), 0777, true);
            $newfile = fopen($directory . "/index.php", w);
            fclose($newfile);
        }
        chmod($directory . "/index.php", 0777);
        //把最新源码写入文件
        file_put_contents($directory . "/index.php", $contents);
        $newUrl = 'http://test.ehuiben.cn/api/upgradeCompanyTemplate?';
        $newUrl .= 'time=' . $_POST['time'];
        $newUrl .= '&did=' . $_POST['did'];
        $newUrl .= '&token=' . md5($userToken . $_POST['time']);
        $companyContents = file_get_contents($newUrl);
        file_put_contents($directory . "/company.php", $companyContents);
        break;
    }
}

?>